home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbcomm.arc / FUNKEY.INC < prev    next >
Text File  |  1989-06-30  |  9KB  |  224 lines

  1.  
  2.    { File: FUNKEY.INC }
  3.    {  Written by: Stew Stryker   for CP/M    09/08/84
  4.  
  5.                  Converted to MS-DOS        01/30/85 }
  6.    { The only changes made were in the interrupt number, from 40 to 24. }
  7.  
  8.    { Declared set of function key codes for array pointers, instead of
  9.      looping until the codes matched, for improved speed.
  10.      - 4/17/85 - Stew Stryker }
  11.  
  12.  
  13.    Const
  14.       CharEntered = 255;
  15.  
  16.    TYPE
  17.  
  18.       FunKeyCode = ( HELP, KDO, COMPOSE, PRINT, DUM4, F4, DUM6,
  19.                      INTERRUPT, DUM8, RESUME, DUM10, CANCEL, DUM12,
  20.                      MAIN, DUM14, KEXIT, DUM16, OPTIONS, DUM18, F17,
  21.                      DUM20, F18, DUM22, F19, DUM24, F20, DUM26, FIND,
  22.                      DUM28, INSERT, DUM30, REMOVE, DUM32, SELECT, DUM34,
  23.                      PREV, DUM36, NEXT, DUM38, UP, DUM40, DOWN, DUM42,
  24.                      RIGHT, DUM44, LEFT, DUM46, KEY0, DUM48, DUM49,
  25.                      KEY1, DUM51, DUM52, KEY2, DUM54, DUM55, KEY3,
  26.                      DUM57, DUM58, KEY4, DUM60, DUM61, KEY5, DUM63,
  27.                      DUM64, KEY6, DUM66, DUM67, KEY7, DUM69, DUM70,
  28.                      KEY8, DUM72, DUM73, KEY9, DUM75, DUM76, KEYMINUS,
  29.                      DUM78, DUM79, KEYCOMMA, DUM81, DUM82, KEYPERIOD,
  30.                      DUM84, DUM85, KEYENTER, DUM87, DUM88, PF1, DUM90,
  31.                      DUM91, PF2, DUM93, DUM94, PF3, DUM96, DUM97,
  32.                      PF4, DUM99, DUM100, BREAK);
  33.  
  34.  
  35.    VAR
  36.       InChar : Char;
  37.       InString : STR80;
  38.       FunKeys : ARRAY[FunKeyCode] OF STR80;
  39.       FunShiftCode : Integer;
  40.       FunCode : FunKeyCode;
  41.  
  42.  
  43.    FUNCTION Level2Key(Var InString : Char) : Boolean;
  44.       { This uses level 2 console in calls to get input characters }
  45.       { You should NOT mix Level 2 inputs with the above ReadKey }
  46.       { inputs, as you'll screw up the level 2 key buffer. }
  47.       { This routine is only included to clear the level 2 keyboard }
  48.       { buffer. }
  49.  
  50.       BEGIN
  51.          InString := ^@;
  52.          __SaveRegisters := __Registers;
  53.          { Check if a character has been entered from the keyboard }
  54.          __Registers.CX := 0;
  55.          __Registers.DI := 2;
  56.          Intr(24,__Registers);
  57.  
  58.          { If a char has been entered, decode it }
  59.          If __Registers.CL = CharEntered Then
  60.             Begin
  61.                { A character has been entered }
  62.                Level2Key := True;
  63.                InString := CHR(__Registers.AL);
  64.                END { If a key was pressed }
  65.             Else Level2Key := False; { A key wasn't pressed }
  66.  
  67.          __Registers := __SaveRegisters;
  68.          END; { Function Level2Key }
  69.  
  70.  
  71.    FUNCTION ReadKey : Boolean;
  72.  
  73.       Var
  74.          TempChar : Char;
  75.  
  76.       BEGIN
  77.          InString := '';   { If a char available, it's put in here }
  78.          FunCode := DUM4;  { Set dummy value, is checked on return }
  79.          { Check if a character has been entered from the keyboard }
  80.          __SaveRegisters := __Registers;
  81.          __Registers.CX := 0;
  82.          __Registers.DI := 6;
  83.          Intr(24,__Registers);
  84.  
  85.          { If a char has been entered, decode it and print it }
  86.          IF __Registers.CL = CharEntered
  87.             Then Begin
  88.                { A character has been entered }
  89.                ReadKey := True;
  90.                FunShiftCode := __Registers.AH;  { Save Shift status }
  91.  
  92.                { Check if they entered a function key }
  93.                IF (__Registers.AH And 1) = 1   { i.e. the value is odd }
  94.                   Then
  95.                      Begin
  96.                         { A function key was pressed }
  97.                         FunCode := FunKeyCode(__Registers.AL);
  98.                         InString := FunKeys[FunCode];
  99.                         End { If this was a function key }
  100.                   Else
  101.                      { A non-function key was entered, save it. }
  102.                      InString := CHR(__Registers.AL);
  103.                End { If a key was pressed }
  104.             Else If __Registers.CL = 1
  105.                Then Begin { A character was received in the Level 2 buffer }
  106.                   ReadKey := True;
  107.                   While Level2Key(InChar) Do
  108.                      InString := Instring + InChar;
  109.                   End
  110.                Else ReadKey := False;
  111.  
  112.  
  113.          __Registers := __SaveRegisters;
  114.          END; { Function ReadKey }
  115.  
  116.  
  117.    Procedure ClearLevel2Buffer;
  118.       { To clear the level 2 keyboard input buffer, we'll read }
  119.       { the level 2 buffer until it's empty; or until we've read }
  120.       { a ridulously large number of characters. }
  121.  
  122.       Var
  123.          Counter : Integer;
  124.  
  125.       Begin
  126.          Counter := 0;
  127.          While (Level2Key(InChar)) And (Counter < 255) Do;
  128.          End; { Procedure ClearLevel2Buffer }
  129.  
  130.  
  131.    Procedure NumericKeypadMode;
  132.       { Define numeric keypad with numeric keypad strings }
  133.       Begin
  134.          FunKeys[KEY0] := '0';          { KEY0 }
  135.          FunKeys[KEY1] := '1';          { KEY1 }
  136.          FunKeys[KEY2] := '2';          { KEY2 }
  137.          FunKeys[KEY3] := '3';          { KEY3 }
  138.          FunKeys[KEY4] := '4';          { KEY4 }
  139.          FunKeys[KEY5] := '5';          { KEY5 }
  140.          FunKeys[KEY6] := '6';          { KEY6 }
  141.          FunKeys[KEY7] := '7';          { KEY7 }
  142.          FunKeys[KEY8] := '8';          { KEY8 }
  143.          FunKeys[KEY9] := '9';          { KEY9 }
  144.          FunKeys[KEYMINUS] := '-';          { KEY- }
  145.          FunKeys[KEYCOMMA] := ',';          { KEY, }
  146.          FunKeys[KEYPERIOD] := '.';          { KEY. }
  147.          FunKeys[KEYENTER] := ^M;          { KEYENTER }
  148.          End; { NumericKeypadMode }
  149.  
  150.  
  151.    Procedure ApplicationKeypadMode;
  152.       { Define numeric keypad with VT100 application keypad strings }
  153.       Begin
  154.          FunKeys[KEY0] := ^[+'Op';          { KEY0 }
  155.          FunKeys[KEY1] := ^[+'Oq';          { KEY1 }
  156.          FunKeys[KEY2] := ^[+'Or';          { KEY2 }
  157.          FunKeys[KEY3] := ^[+'Os';          { KEY3 }
  158.          FunKeys[KEY4] := ^[+'Ot';          { KEY4 }
  159.          FunKeys[KEY5] := ^[+'Ou';          { KEY5 }
  160.          FunKeys[KEY6] := ^[+'Ov';          { KEY6 }
  161.          FunKeys[KEY7] := ^[+'Ow';          { KEY7 }
  162.          FunKeys[KEY8] := ^[+'Ox';          { KEY8 }
  163.          FunKeys[KEY9] := ^[+'Oy';          { KEY9 }
  164.          FunKeys[KEYMINUS] := ^[+'Om';          { KEY- }
  165.          FunKeys[KEYCOMMA] := ^[+'Ol';          { KEY, }
  166.          FunKeys[KEYPERIOD] := ^[+'On';          { KEY. }
  167.          FunKeys[KEYENTER] := ^[+'OM';          { KEYENTER }
  168.          End; { ApplicationKeypadMode }
  169.          
  170.  
  171.    Function GetInitFunkey(Code : FunKeyCode) : STR80;
  172.       Begin
  173.          Case Code Of
  174.       HELP:    GetInitFunkey := ^[+'[28~';        { HELP }
  175.       KDO:     GetInitFunkey := ^[+'[29~';         { DO }
  176.       COMPOSE:    GetInitFunkey := ^[+'[10~';     { COMPOSE }
  177.       PRINT:      GetInitFunkey := '';              { PRINT }
  178.       F4:      GetInitFunkey := ^[+'[14~';          { F4 }
  179.       INTERRUPT:     GetInitFunkey := ^[+'[17~';   { INTERRUPT }
  180.       RESUME:     GetInitFunkey := ^[+'[18~';      { RESUME }
  181.       CANCEL:     GetInitFunkey := ^[+'[19~';      { CANCEL }
  182.       MAIN:    GetInitFunkey := ^[+'[20~';        { MAIN }
  183.       KEXIT:      GetInitFunkey := ^[+'[21~';       { EXIT }
  184.       OPTIONS:    GetInitFunkey := ^[+'[26~';     { OPTIONS }
  185.       F17:     GetInitFunkey := ^[+'[31~';         { F17 }
  186.       F18:     GetInitFunkey := ^[+'[32~';         { F18 }
  187.       F19:     GetInitFunkey := ^[+'[33~';         { F19 }
  188.       F20:     GetInitFunkey := ^[+'[34~';         { F20 }
  189.       FIND:    GetInitFunkey := ^[+'[1~';         { FIND }
  190.       INSERT:     GetInitFunkey := ^[+'[2~';       { INSERT }
  191.       REMOVE:     GetInitFunkey := ^[+'[3~';       { REMOVE }
  192.       SELECT:     GetInitFunkey := ^[+'[4~';       { SELECT }
  193.       PREV:    GetInitFunkey := ^[+'[5~';         { PREV }
  194.       NEXT:    GetInitFunkey := ^[+'[6~';         { NEXT }
  195.       UP:      GetInitFunkey := ^[+'[A';            { UP }
  196.       DOWN:    GetInitFunkey := ^[+'[B';          { DOWN }
  197.       RIGHT:      GetInitFunkey := ^[+'[C';         { RIGHT }
  198.       LEFT:    GetInitFunkey := ^[+'[D';          { LEFT }
  199.       PF1:     GetInitFunkey := ^[+'OP';           { PF1 }
  200.       PF2:     GetInitFunkey := ^[+'OQ';           { PF2 }
  201.       PF3:     GetInitFunkey := ^[+'OR';           { PF3 }
  202.       PF4:     GetInitFunkey := ^[+'OS';           { PF4 }
  203.       BREAK:      GetInitFunkey := '';              { BREAK }
  204.       Else Begin End;
  205.       End; { Case Statement }
  206.       End; { Function GetInitFunkey }
  207.       
  208.  
  209.    PROCEDURE InitFunkeys;
  210.       Var
  211.          CodeCount : FunKeyCode;
  212.       BEGIN
  213.       { Define values of function keys }
  214.  
  215.       For CodeCount := HELP To BREAK Do
  216.          FunKeys[CodeCount] := GetInitFunkey(CodeCount);
  217.  
  218.       NumericKeypadMode;   { Initially define keypad as numeric }
  219.       ClearLevel2Buffer;   { In preparation for Level 1 inputs }
  220.       { Thank God the definitions are done. }
  221.       END;  { Procedure InitFunkeys }
  222.  
  223.  
  224.